<template>
	<div>
		<h2 style="margin-bottom: 10px">
			不确定度理论法（汽车与二轮摩托车或自行车质心的前侧侧面碰撞）
		</h2>
		<h4 style="margin-bottom: 10px">不确定输入参数范围</h4>
		<div class="title">
			<div>均值</div>
			<div>最大离差</div>
			<div>包含因子</div>
		</div>
		<el-form
			:model="form"
			:rules="rules"
			ref="formRef"
			label-width="220px"
			label-position="left"
			:inline="true"
		>
			<el-form-item label="滑动附着系数 (o)" prop="o">
				<el-form-item prop="o">
					<el-input class="ipt" v-model="form.o" />
				</el-form-item>
				<el-form-item prop="o1">
					<el-input class="ipt" v-model="form.o" />
				</el-form-item>
				<el-form-item prop="o2">
					<el-input class="ipt" v-model="form.o" />
				</el-form-item>
			</el-form-item>
			<el-form-item label="碰撞后滑移距离 (s)" prop="s">
				<el-form-item prop="s">
					<el-input class="ipt" v-model="form.s" />
				</el-form-item>
				<el-form-item prop="s1">
					<el-input class="ipt" v-model="form.s1" />
				</el-form-item>
				<el-form-item prop="s2">
					<el-input class="ipt" v-model="form.s2" />
				</el-form-item>
			</el-form-item>
			<el-form-item label="滑移偏向角 (oDegrees)" prop="oDegrees">
				<el-form-item prop="oDegrees">
					<el-input class="ipt" v-model="form.oDegrees" />
				</el-form-item>
				<el-form-item prop="oDegrees1">
					<el-input class="ipt" v-model="form.oDegrees1" />
				</el-form-item>
				<el-form-item prop="oDegrees2">
					<el-input class="ipt" v-model="form.oDegrees2" />
				</el-form-item>
			</el-form-item>
		</el-form>
		<h4 style="margin-bottom: 10px">输出结果</h4>
		<div class="footer">
			<div>
				<el-form-item label="速度下界 (km/h)">
					<el-input class="ipt" v-model="result" type="number" />
				</el-form-item>
				<el-form-item label="速度上界 (km/h)">
					<el-input class="ipt" v-model="result1" type="number" />
				</el-form-item>
			</div>
			<div style="margin-left: 220px">
				<el-button type="primary" @click="calculateSpeed">不确定分析</el-button>
			</div>
		</div>
	</div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
const formRef = ref(null);

const form = ref({
	g: 9.8,
	k: 1,
	o: null,
	s: null,
	oDegrees: null,
	o1: null,
	s1: null,
	oDegrees1: null,
	o2: null,
	s2: null,
	oDegrees2: null
});
const result = ref(null);
const result1 = ref(null);
const rules = {
	g: [{ required: true, message: "请输入重力加速度", trigger: "blur" }],
	o: [{ required: true, message: "请输入滑动附着系数", trigger: "blur" }],
	k: [{ required: true, message: "请输入附着系数修正值", trigger: "blur" }],
	s: [{ required: true, message: "请输入碰撞后滑移距离", trigger: "blur" }],
	oDegrees: [{ required: true, message: "请输入滑移偏向角", trigger: "blur" }]
};

const calculateSpeed = () => {
	formRef.value.validate((valid) => {
		if (valid) {
			const { g, o, k, s, oDegrees } = form.value;
			const toRadians = (degrees) => degrees * (Math.PI / 180);
			const oRadians = toRadians(oDegrees);
			const v = Math.sqrt(2 * g * o * k * s) * Math.cos(oRadians) * 3.6;
			result.value = v;
			result1.value = v;
		}
	});
};
</script>
<style scoped>
.ipt {
	width: 120px;
}
.title {
	display: flex;
	align-items: center;
	padding-left: 255px;
	margin-bottom: 20px;
	div {
		margin-right: 106px;
	}
}
.footer {
	display: flex;
	align-items: center;
}
</style>
